<template>
  <div>
    <h1 class="title">生成F码</h1>
    <div class="body">
      <div class="body_title">
        <span>生成F码</span>
      </div>
      <div class="main">
        <div class="search_div">
          <div class="search">
            <input class="input" v-model="codeNumber" type="number" autofocus="autofocus" placeholder="请输入生成F码的个数"/>
            <span class="button" @click="createFCode">点击生成F码</span>
          </div>
        </div>
        <div class="body_title">
          <span>F码列表</span>
          <span class="download" @click="createExcel">生成Excel表格</span>
        </div>
        <div class="main">
          <ul>
            <li class="item" v-for="item in fcode">
              <span>{{item.value}}</span>
              <span class="used" v-show="item.isUse==true">已用</span>
              <span class="used unused" v-show="item.isUse==false">未用</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "fcode",
    data() {
      return {
        codeNumber: '',
        fcode: [],
        page: {
          pageIndex: 1,
          pageSize: 1000
        }
      }
    },
    created() {
      this.initFCode()
    },
    methods: {
      initFCode() {
        this.$post('/fCode/admin/fCode/list', this.page, res => {
            this.fcode = res
          }
        )
      },
      createFCode() {
        let num = this.codeNumber
        if (num == undefined || num <= 0) {
          this.$message({
            message: '请输入数量',
            type: 'warning'
          });
          return
        }
        this.$post('/fCode/admin/create', {total: num}, res => {
          this.initFCode()
        })
      }
      ,
      createExcel() {
        let pageIndex = this.page.pageIndex
        let pageSize = this.page.pageSize
        let url = this.$mainUrl
        location.href = `${url}/fCode/admin/exportExcel?pageIndex=${pageIndex}&pageSize=${pageSize}`
      }
    }
  }
</script>

<style scoped>
  .used {
    font-size: 10px;
    display: inline-block;
    background-color: #DCDFE6;
    padding: 0 5px;
    -webkit-user-select: none;
    user-select: none;
  }

  .unused {
    color: red;
  }

  .title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 20px 0;
  }

  .body {
    border: 1px solid #EBEEF5;
  }

  .body .body_title {
    background-color: #EEEEEE;
    padding: 5px 10px;
  }

  .search_div {
    margin: 30px 0;
    text-align: center;
  }

  .search {
    height: 35px;
    display: inline-block;
  }

  .search .input {
    float: left;
    height: 84%;
    padding: 2px 10px;
    width: 340px;
    border: 1px solid #409EFF;
    outline: none;
  }

  .search .button {
    float: left;
    right: 0;
    height: 35px;
    line-height: 35px;
    background-color: #409EFF;
    font-size: 20px;
    color: #fff;
    padding: 0 5px;
    cursor: pointer;
  }

  .body_title .download {
    float: right;
    font-size: 12px;
    line-height: 20px;
    cursor: pointer;
  }

  .body_title .download:hover {
    color: #409EFF;
  }

  .body .main .main {
    text-align: left;
    overflow: hidden;
    white-space: pre-wrap;
  }

  .body .main .main ul {
    list-style: none;
  }

  .body .main .main ul li {
    display: inline-block;
    margin: 0 10px;
    padding: 3px 15px;
  }
</style>
